package com.itboye.ihomebank.util;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.itboye.ihomebank.R;

/**
 * Created by 10211 on 2018/1/23.
 */
public class UIAlertViewTwo extends Dialog {
    private Context context;
    private String one;
    private String two;
    private String three;
    private ClickListenerInterface clickListenerInterface;

    public UIAlertViewTwo(Context context, String one, String two,String three) {
        super(context, R.style.UIAlertViewStyle);

        this.context = context;
        this.one = one;
        this.two = two;
        this.three = three;
    }

    public interface ClickListenerInterface {
        public void doOne();
        public void doTwo();
        public void doThree();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        inite();
    }

    public void inite() {
        LayoutInflater inflater = LayoutInflater.from(context);
        View view = inflater.inflate(R.layout.ui_alert_view_two, null);
        setContentView(view);

        TextView tvZuhu = (TextView) view.findViewById(R.id.tvZuhu);
        TextView tvPutong = (TextView) view.findViewById(R.id.tvPutong);
        TextView tvQuxiao = (TextView) view.findViewById(R.id.tvQuxiao);
        tvZuhu.setText(one);
        tvPutong.setText(two);
        tvQuxiao.setText(three);

        tvZuhu.setOnClickListener(new UIAlertViewTwo.clickListener());
        tvPutong.setOnClickListener(new UIAlertViewTwo.clickListener());
        tvQuxiao.setOnClickListener(new UIAlertViewTwo.clickListener());

        Window dialogWindow = getWindow();
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        DisplayMetrics d = context.getResources().getDisplayMetrics();

        lp.width = (int) (d.widthPixels * 0.8);
        dialogWindow.setAttributes(lp);
    }

    public void setClicklistener(ClickListenerInterface clickListenerInterface) {
        this.clickListenerInterface = clickListenerInterface;
    }

    private class clickListener implements View.OnClickListener {

        public void onClick(View v) {
            int id = v.getId();
            switch (id) {
                case R.id.tvZuhu:
                    clickListenerInterface.doOne();
                    break;
                case R.id.tvPutong:
                    clickListenerInterface.doTwo();
                    break;
                case R.id.tvQuxiao:
                    clickListenerInterface.doThree();
                    break;
                default:
                    break;
            }
        }
    }
    ;
}
